package com.mk.episodecalendar;
import android.content.Context;

import com.mk.episodecalendar.security.AuthModule;

public class Global {
	public static AuthModule AuthModule;
	public static User CurrentUser;
	public static ApplicationPrecferences ApplicationPrecferences;
	public static EpisodeRepository EpisodeRepository;
	public static LayoutObjectFactory LayoutObjectFactory;
	
	public static void setUpGlobal(Context context)
	{
		AuthModule = new AuthModule();
		ApplicationPrecferences = new ApplicationPrecferences(context);
		EpisodeRepository = new EpisodeRepository();
		LayoutObjectFactory = new LayoutObjectFactory();
	}
	
	public static void setCurrentUser(String userName, Boolean isAuthenticated)
	{
		CurrentUser = new User(userName);
    	CurrentUser.setIsAuthenticated(isAuthenticated);
	}
	
	public static void signOutCurrentUser()
	{
		CurrentUser.setIsAuthenticated(false);
		ApplicationPrecferences.setAutoLogin(false);
		ApplicationPrecferences.setUserName("");
		ApplicationPrecferences.setAuthKey("");
		CurrentUser = null;
	}
	
	public static void AutoLoginUser()
	{
		String userName = ApplicationPrecferences.getUserName();
		if(ApplicationPrecferences.getAutoLogin() && userName != null && userName != "")
		{
			setCurrentUser(userName, true);
		}
	}
}
